<?php
namespace Action;
use HY\Action;
!defined('HY_PATH') && exit('HY_PATH not defined.');
class Topo extends HYBBS {

    //类中使用的路径
    //task2 是为第二代加速设计的 文件使用透明转发http使用代理
    //系统平台使用华为欧拉 LS 版本SP1
    //20230212
    public function __construct() {
        parent::__construct();
        //{hook a_post_init}
        if(!IS_LOGIN){
            if(IS_AJAX && IS_POST){
                die($this->json(array('error'=>false,'info'=>'请登录后再操作')));
            }
            else{
                header("location: ". HYBBS_URLA('user','login'));
                die;
            }
        }
    }

    //获拓扑数据
    public function getTopoData(){
        $op = X("get.op","file");
        //$this->json(M("Sysinfo")->getIps($op));
        if($op == "file"){
            $nodes = S("fhl_nodes")->query('select * from hy_fhl_nodes n where  n.service  = \'file\'')->fetchALL();
            $links = S("fhl_links")->query('select * from hy_fhl_links l join hy_fhl_task t
								on l.tkid = t.tkid and l.service  = \'file\'')->fetchALL();
        }
        $this->json(["state"=>true,"data"=>[
            'nodes'=>$nodes,
            'links'=>$links
        ]]);
    }
    public function editNodePosition(){
        $nid = intval(X("post.nid"));
        $x = intval(X("post.x",1));
        $y = intval(X("post.y",1));
        S("fhl_nodes")->update([
            'x'=>$x,
            'y'=>$y
        ],[
            'nid'=>$nid
        ]);
        $this->json([
            'state'=>true,
            'position'=>[$x,$y]
        ]);
    }



}
